package com.xilihui.xlh.business.requests;

import android.content.Context;

import com.xilihui.xlh.business.entities.AddOrderEntity;
import com.xilihui.xlh.business.entities.AppointmentEntity;
import com.xilihui.xlh.business.entities.BalanceEntity;
import com.xilihui.xlh.business.entities.CartListEntity;
import com.xilihui.xlh.business.entities.CheckEntity;
import com.xilihui.xlh.business.entities.EvaluateEntity;
import com.xilihui.xlh.business.entities.GoodDetailsEntity;
import com.xilihui.xlh.business.entities.HistoryEntity;
import com.xilihui.xlh.business.entities.MyOrderEntity;
import com.xilihui.xlh.business.entities.PayingEntity;
import com.xilihui.xlh.business.entities.SpecEntity;
import com.xilihui.xlh.business.entities.TakeCodeEntity;
import com.xilihui.xlh.business.entities.TakeGoodsEntity;
import com.xilihui.xlh.constant.StrConst;
import com.xilihui.xlh.core.app.BaseEntity;
import com.xilihui.xlh.core.http.HttpManager;
import com.xilihui.xlh.core.util.SPUtil;
import com.xilihui.xlh.core.util.SignUtil;
import com.xilihui.xlh.core.util.TimeFormatUtil;

import java.util.HashMap;

import rx.Observable;

/**
 * Created by Administrator on 2018/6/25.
 */

public class MyAppointmentRequest {
    
    public static MyAppointmentService service = HttpManager.getRetrofit().create(MyAppointmentService.class);

    /**
     * 我的预约
     * @param context
     * @param status
     * @param page
     * @return
     */
    public static Observable<AppointmentEntity> myAppointment(Context context, int status, int page){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.myAppoint(access_token,status,page);
    }

    /**
     * 历史记录
     * @param context
     * @param status
     * @param page
     * @return
     */
    public static Observable<HistoryEntity> history(Context context, int status, int page){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.history(access_token,status,page);
    }

    /**
     * 提交评价
     * @param context
     * @param agent_id
     * @param wa_id
     * @param zan_num
     * @param content
     * @return
     */
    public static Observable<BaseEntity> submitComment(Context context,String agent_id,String wa_id,float zan_num,
                                                       String content){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.submitComment(access_token,agent_id,wa_id,zan_num,content);
    }

    /**
     * 我的预约-评价记录
     * @param context
     * @return
     */
    public static Observable<EvaluateEntity> evaluateList(Context context){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.evaluateList(access_token);
    }

    /**
     * 我的预约-取消预约
     * @param context
     * @param id
     * @return
     */
    public static Observable<BaseEntity> cancelAppoint(Context context,String id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.cancelAppoint(access_token,id);
    }

    /**
     * 我的预约-正在进行付款
     * @param sa_id
     * @return
     */
    public static Observable<PayingEntity> paying(Context context,String sa_id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.paying(access_token,sa_id);
    }

    /**
     * 我的预约-撤销预约
     * @param context
     * @param id
     * @return
     */
    public static Observable<BaseEntity> deletePaying(Context context,String id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.deletePaying(access_token,id);
    }

    /**
     * 我的预约-历史记录-删除
     * @param context
     * @param id
     * @return
     */
    public static Observable<BaseEntity> deleteDistory(Context context,String id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.deleteHistory(access_token,id);
    }

    /**
     * 仓库领货 
     * @param context
     * @param id
     * @param cate_id
     * @param page
     * @return
     */
    public static  Observable<TakeGoodsEntity> takeGoods(Context context, String id, String cate_id, int page,String wa_id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.takeGoods(access_token,id,cate_id,page,wa_id);
    }

    /**
     * 仓库领货 领用
     * @param context
     * @param id
     * @return
     */
    public static Observable<GoodDetailsEntity> goodDetails(Context context,String id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.goodDetails(access_token,id);
    };
    
    public static Observable<GoodDetailsEntity> goodSpce(Context context,String id,String agent_id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.goodSpec(access_token,id,agent_id);
    }

    /**
     * 仓库领货 规格
     * @param key
     * @return
     */
    public static Observable<SpecEntity> spce(String key,String goods_id){
        return service.spec(key,goods_id);
    }

    /**
     * 仓库领货 加入清单
     * @param context
     * @param good_id
     * @param goods_num
     * @param item_id
     * @return
     */
    public static Observable<BaseEntity> joinCart(Context context,String good_id,String goods_num,String item_id,String agent_id,String wa_id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.addCart(access_token,good_id,goods_num,item_id,agent_id,wa_id);
    }

    /**
     * 仓库领货 清单
     * @param context
     * @param id
     * @return
     */
    public static Observable<CartListEntity> cartlist(Context context,String id,String wa_id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.cartlist(access_token,id,wa_id);
    }

    /**
     * 勾选单个商品
     * @param context
     * @param id
     * @param selected
     * @return
     */
    public static Observable<CheckEntity> checkGood(Context context, String agent_id, String id, String selected){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.checkGood(access_token,agent_id,id,selected);
    }

    /**
     * 勾选全部 或 取消全部
     * @param context
     * @param selected
     * @return
     */
    public static Observable<CheckEntity> checkAll(Context context,String selected,String agent_id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.checkAll(access_token,selected,agent_id);
    };

    /**
     * 更新购物车商品
     * @param context
     * @return
     */
    public static Observable<BaseEntity> updateCart(Context context,String id,String agent_id,String item_id,String goods_num,String wa_id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.updateCart(access_token,id,agent_id,item_id,goods_num,wa_id);
    }

    /**
     * 清单 结算
     * @param context
     * @param id
     * @return
     */
    public static Observable<BalanceEntity> jiesuan(Context context,String id,String wa_id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.jiesuan(access_token,id,wa_id);
    }

    /**
     * 立即结算
     * @param id
     * @param goods_id
     * @param item_id
     * @param goods_num
     * @return
     */
    public static Observable<BalanceEntity> lijijiesuan(String id,String goods_id,String item_id,String goods_num){
        String app_key = StrConst.app_key;
        String temptime = TimeFormatUtil.getTimestamp();

        HashMap<String,String> map = new HashMap<>();
        map.put("id",id);
        map.put("goods_id",goods_id);
        map.put("item_id",item_id);
        map.put("goods_num",goods_num);
        map.put("app_key",app_key);
        map.put("temptime",temptime);
        return service.lijijiesuan(id,goods_id,item_id,goods_num,temptime,app_key,SignUtil.sign(map));
    }

    /**
     * 删除 商品
     * @param context
     * @param id
     * @return
     */
    public static Observable<BaseEntity> deleteGoods(Context context,String id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        String app_key = StrConst.app_key;
        String temptime = TimeFormatUtil.getTimestamp();
        
        HashMap<String,String> map = new HashMap<>();
        map.put("access_token",access_token);
        map.put("id",id);
        map.put("app_key",app_key);
        map.put("temptime",temptime);
        
        return service.deleteGoods(access_token,id,SignUtil.sign(map),temptime,app_key);
    }


    /**
     * 支付
     * @param context
     * @param agent_id
     * @param wa_id
     * @return
     */
    public static Observable<AddOrderEntity> addOrder(Context context,String agent_id,String wa_id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        String app_key = StrConst.app_key;
        String temptime = TimeFormatUtil.getTimestamp();
        
        HashMap<String,String> map = new HashMap<>();
        map.put("access_token",access_token);
        map.put("agent_id",agent_id);
        map.put("wa_id",wa_id);
        map.put("temptime",temptime);
        map.put("app_key",app_key);
        
        return service.addOrder(access_token,agent_id,wa_id,temptime,app_key,SignUtil.sign(map));
    }


    /**
     * 仓库领货 我的清单
     * @param context
     * @param wa_id
     * @param agent_id
     * @param status
     * @param page
     * @return
     */
    public static Observable<MyOrderEntity> myOrder(Context context,String wa_id,String agent_id,
                                                    String status,int page){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.myOrder(access_token,wa_id,agent_id,status,page);
    }

    /**
     * 我的清单 付款
     * @param context
     * @param id
     * @return
     */
    public static Observable<AddOrderEntity> myPay(Context context,String id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        String app_key = StrConst.app_key;
        String temptime = TimeFormatUtil.getTimestamp();

        HashMap<String,String> map = new HashMap<>();
        map.put("access_token",access_token);
        map.put("id",id);
        map.put("temptime",temptime);
        map.put("app_key",app_key);
        
        return service.myPay(access_token,id,temptime,app_key,SignUtil.sign(map));
    }

    /**
     * 立即结算 付款
     * @param context
     * @return
     */
    public static Observable<AddOrderEntity> lijijiesuanPay(Context context,String goods_id,String goods_num,
                                                            String wa_id,String item_id,String agent_id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        String app_key = StrConst.app_key;
        String temptime = TimeFormatUtil.getTimestamp();
        
        HashMap<String,String> map = new HashMap<>();
        map.put("access_token",access_token);
        map.put("goods_id",goods_id);
        map.put("goods_num",goods_num);
        map.put("wa_id",wa_id);
        map.put("item_id",item_id);
        map.put("agent_id",agent_id);
        map.put("temptime",temptime);
        map.put("app_key",app_key);
        
        return service.lijijiesuanPay(access_token,goods_id,goods_num,wa_id,item_id,agent_id,temptime,app_key,SignUtil.sign(map));
    }

    /**
     * 我的清单 取消订单
     * @param context
     * @param id
     * @return
     */
    public static Observable<BaseEntity> cancelOrder(Context context,String id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.cancelOrder(access_token,id);
    }

    /**
     * 我的清单 删除订单
     * @param context
     * @param id
     * @return
     */
    public static Observable<BaseEntity> deleteOrder(Context context,String id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.deleteOrder(access_token,id);
    }

    /**
     * 我的清单 领货
     * @param context
     * @param id
     * @return
     */
    public static Observable<TakeCodeEntity> takeCode(Context context,String id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.takeCode(access_token,id);
    }
    
}
